<?php
/* SVN FILE: $Id$ */
/**
 * Template Name: Sitemap
 *
 * This is the template file for generating a HTML sitemap
 *
 * @package        CPConstruction
 * @subpackage     Content
 * @copyright      CP Construction (Gwent) Ltd <http://www.cpconstruction.co.uk/> 2012
 * @author         Richard Perry <http: //www.perry-online.me.uk/>
 * @since          Release 2.0.1
 * @version        $Rev$
 * @modifiedby     $LastChangedBy$
 * @lastmodified   $Date: 2012-09-26 10:37:50 +0100 (Wed, 26 Sep 2012) $
 *
 * @todo           ToDo List
 *                  -
 */
 
get_header(); // Load the header.php template. ?>

            <div id="container">
                <div id="content" >
                    <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
                        <header class="entry-header">
                            <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>">
                                <?php the_title(); ?>
                            </a></h2>
                        </header>
                        <div class="entry-content siteMap">
<!-- ----------------- Display Pages ----------------- -->
                            <h3 id='pages'>Pages</h3>
                            <ul>
                                <?php
                                // Add pages seprated with comma[,] that you'd like to hide to display on sitemap
                                wp_list_pages(
                                    array(
                                        'exclude' => '',
                                        'title_li' => '',
                                    )
                                );
                                ?>
                            </ul>
<?php /*<!-- ----------------- Display Categories ----------------- -->
                            <h3 id='categories'>Categories</h3>
                            <ul>
                                <?php wp_list_cats("sort_column=name&optioncount=1&hierarchical=0"); ?>
                            </ul> */ ?>
<!-- ----------------- Display Post with its relative category ----------------- -->
                            <h3 id='posts'>Posts</h3>
                            <table id=arc>
                                <?php
                                $query = "SELECT YEAR(post_date) AS `year`, 
                                                MONTH(post_date) as `month`, 
                                                DAYOFMONTH(post_date) as `dayofmonth`, 
                                                ID, 
                                                post_name, 
                                                post_title 
                                            FROM $wpdb->posts 
                                            WHERE post_type = 'post' 
                                            AND post_status = 'publish' 
                                            ORDER BY post_date DESC";
                                $key = md5($query);
                                $cache = wp_cache_get( 'mp_archives' , 'general');
                                if ( !isset( $cache[ $key ] ) ) {
                                    $arcresults = $wpdb->get_results($query);
                                    $cache[ $key ] = $arcresults;
                                    wp_cache_add( 'mp_archives', $cache, 'general' );
                                } else {
                                    $arcresults = $cache[ $key ];
                                }
                                if ($arcresults) {
                                    $last_year = 0;
                                    $last_month = 0;
                                    foreach ( $arcresults as $arcresult ) {
                                        $year = $arcresult->year;
                                        $month = $arcresult->month;
                                        if ($year != $last_year) {
                                            $last_year = $year;
                                            $last_month = 0;
                                ?>
                                <tr class='year'>
                                    <th><?php echo $arcresult->year; ?></th>
                                </tr>
                                <?php
                                        }
                                        if ($month != $last_month) {
                                            $last_month = $month;
                                ?>
                                <tr class='archive'>
                                    <th><?php echo $wp_locale->get_month($arcresult->month); ?></th>
                                    <td></td>
                                </tr>
                                <?php
                                        }
                                ?>
                                <tr class='archive'>
                                    <th><?php echo $arcresult->dayofmonth; ?></th>
                                    <td id=p<?php echo $arcresult->ID; ?>>
                                        <a href='<?php echo get_permalink( $arcresult->ID ); ?>'
                                            title='<?php echo strip_tags(apply_filters('the_title', $arcresult->post_title)); ?>'>
                                            <?php echo strip_tags(apply_filters('the_title', $arcresult->post_title)); ?>
                                        </a>
                                    </td>
                                </tr>
                                <?php
                                    }
                                }
                                ?>
                            </table>
                        </div>
                    </article>
                </div>
            </div>
<?php get_sidebar(); // Load the sidebar.php template. ?>
<?php get_footer(); // Load the footer.php template. ?>